//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "server\fn_serverSetupAssassinate.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_object","_action","_parameters","_killed_msg","_shared_variable","_killed_code","_evt_idx"];
DEFAULT_PARAM(_object,TMF_REGISTER_OBJECT,objNull);
DEFAULT_PARAM(_action,TMF_REGISTER_ACTION,[]);
DEFAULT_PARAM(_instance_id,TMF_REGISTER_INSTANCE,TMF_SERVER_INSTANCE_ID);

if (!isnull _object) then {
	_action_id = [_action] call FFUNC(actionGetID);
	TRACE_1("Action",_action);
	_parameters = [_action] call FFUNC(actionGetParams);
	
	if ((_object isKindOf "Man") Or (_object isKindOf "LandVehicle") Or (_object isKindOf "Air") Or (_object isKindOf "Ship")) then {
		_killed_msg = [_parameters, "KILLED_MSG", ""] call CFUNC(hashGet);
		_shared_variable = [_parameters, "SHARED_VAR", ""] call CFUNC(hashGet);
		_killed_code = [_parameters, "KILLED_CODE", ""] call CFUNC(hashGet);
			
		if (typename _killed_msg == typename "") then {_killed_msg = [_killed_msg];};

		_evt_idx = _object addEventHandler ["killed", Format["[_this, %1] call %2;",_action_id,QUOTE(FFUNC(eventObjectiveAssassinate))]];
		[_object,_action,"ASSASSINATE_KILLED_EVENT",_evt_idx] call FFUNC(actionSetLocal);

		if (!isNil "_shared_variable") then {
			if (_shared_variable != "") then {
				[_instance_id,_shared_variable,false] call FFUNC(setMissionJIPVar);
				[QGVAR(all_var), [_instance_id,_shared_variable,false],THIS_FILE_] call NFUNC(callEvent);
			};
		};
	} else {
		ERROR_1("Invalid Class",typeof _object);
	};
} else {
	ERROR("Object not set");
};
TRACE("End");
TMFPROFILERSTOP;